
const mysql = require('../db/mysql')
const relationDao = require('../sql/relationDao')

exports.relation = async (req, res)=>{
    try {
        let row = await mysql(relationDao.selectOne)
        res.success(row[0])
    }catch (e) {
        console.log(e)
        res.status(500).fail('服务器错误')
    }
}


exports.update = async (req, res)=>{
    try {
        let body = {};
        if(req.body.img)body.img = req.body.img;
        if(req.body.address)body.address = req.body.address;
        if(req.body.contact)body.contact = req.body.contact;
        if(req.body.email)body.email = req.body.email;
        if(req.body.postcode)body.postcode = req.body.postcode;
        if(req.body.tel)body.tel = req.body.tel;
        let row = await mysql(relationDao.update, [body, req.body.id]);
        if(row.affectedRows==1) return res.success({}, '修改成功！');
        else return res.fail('修改失败');
    }catch (e) {
        console.log(e)
        res.status(500).fail('服务器错误')
    }
}
